/**
 * @file ListViewAdapter.java
 *
 */
package ar.com.PanteraRosa.Utils;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import ar.com.PanteraRosa.R;

/**
 * @desc
 * @date 08/03/2012
 * @author Fede
 *
 */
public class ListViewAdapter extends ArrayAdapter<ListViewItem> {
    
    private ArrayList<ListViewItem> items;
    private ViewHolder holder;
    
    class ViewHolder {
        TextView title;
    }
    
    public ListViewAdapter(Context context, int textViewResourceId, ArrayList<ListViewItem> items) {
        super(context, textViewResourceId, items);
        this.items = items;
    }
    
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View v = convertView;
        
        if(v == null) {
            LayoutInflater vi = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(R.layout.elementolista, null);
            
            holder = new ViewHolder();
            
            holder.title = (TextView) v.findViewById(R.id.title);
            v.setTag(holder);
        } else {
            holder = (ViewHolder) v.getTag();
        }
        ListViewItem listViewItem = items.get(position);
        
        holder.title.setText(listViewItem.getTitle());
        
        return v;
    }
}